var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    info: null,
    coupon_list:[],
    goods_list:[],
    anli_list:[],
    dianping_list: [],
    tabs: [{ title: '优惠', icon: 'gif' }, { title: '爆款', icon: 'hot' }, { title: '案例', icon: 'log' }, { title: '点评', icon:'review-null'}],
    tabIndex: 0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var t =this
    wx.showLoading({
      title: '加载中',
    })
    setTimeout(function(){
      t.getlist();
    },200)
    
  },
  onShow: function (options){
    
  },
  getlist:function (options){
    //if (typeof (options.shop_id)==undefined) {
      var options = { "shop_id": app.globalData.shop_id }
    //}
    app.ihttpGet('https://www.58zltc.com/api.php/Shop/item/shop_id/' + options.shop_id, res => {
      this.setData({
        info: res.data
      })
    })
    app.ihttpGet('https://www.58zltc.com/api.php/Goods/index/shop_id/' + options.shop_id, res => {
      this.setData({
        goods_list: res.data
      })
    })
    app.ihttpGet('https://www.58zltc.com/api.php/Goods/index/type/jiancai/shop_id/' + options.shop_id, res => {
      this.setData({
        jiancai_list: res.data
      })
    })
    app.ihttpGet('https://www.58zltc.com/api.php/Coupon/index/shop_id/' + options.shop_id, res => {
      this.setData({
        coupon_list: res.data
      })
    })
    app.ihttpGet('https://www.58zltc.com/api.php/Jiancai/anli/shop_id/' + options.shop_id, res => {
      this.setData({
        anli_list: res.data
      })
    })
    setTimeout(function () {
      wx.hideLoading();
    }, 3000)
    
  },
  setTab: function (e) {
    this.setData({
      tabIndex: e.currentTarget.dataset.index
    })
  },
  bindCall: function (e) {
    console.log(e);
    var tel = e.currentTarget.dataset.tel;
    console.log(tel);
    wx.makePhoneCall({
      phoneNumber: tel
    })
  },
  openLocation: function (e) {
    var data = e.currentTarget.dataset;
    wx.openLocation({
      latitude: Number(data.latitude),
      longitude: Number(data.longitude),
      name: data.name,
      address: data.address
    })
  },
  getCoupon: function (e) {
    let that = this;
    const id = e.currentTarget.dataset.id;
    var post_data = {};
    post_data.coupon_id = id;
    post_data.openid = app.globalData.openid;
    app.ihttpPost("https://www.58zltc.com/api.php/Coupon/getCoupon", post_data, function (res) {
      app.iModel(res.data.err_msg);
    })
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    const shop = this.data.info;
    return {
      title: shop.name,
      path: '/pages/jiancai/detail?shop_id=' + shop.shop_id
    }
  }
})